package pl.vm.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import pl.vm.model.Seazon;

@Repository
public class SeazonDao {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public final Seazon get(long id) {
		return (Seazon) sessionFactory.getCurrentSession().get(Seazon.class, id);
	}

	public final void refresh(Seazon entity) {
		sessionFactory.getCurrentSession().refresh(entity);
	}

//	public void save(Seazon entity) {
//		sessionFactory.getCurrentSession().save(entity);
//	}

//	public void saveOrUpdate(Seazon entity) {
//		sessionFactory.getCurrentSession().saveOrUpdate(entity);
//	}

	
	public void merge(Seazon entity) {
		sessionFactory.getCurrentSession().merge(entity);
	}

	public final void delete(Seazon entity) {
		sessionFactory.getCurrentSession().delete(entity);
	}

	public void evict(Seazon entity) {
		sessionFactory.getCurrentSession().evict(entity);
	}

	public void persist(Seazon entity) {
		sessionFactory.getCurrentSession().persist(entity);
	}

	public final void flush() {
		sessionFactory.getCurrentSession().flush();
	}

	public final void clearSession() {
		sessionFactory.getCurrentSession().clear();
	}

	@SuppressWarnings("unchecked")
	public final List<Seazon> loadAll() {
		return sessionFactory.getCurrentSession().createQuery("from Seazon").list();
	}

	public final boolean exists(int id) {
		Criteria criteria = sessionFactory.getCurrentSession()
				.createCriteria(Seazon.class).add(Restrictions.idEq(id));
		criteria.setProjection(Projections.rowCount());
		return (Integer) criteria.uniqueResult() > 0;
	}
}
